from goods.models import SKU
from goods.serializers import HotSerializer

from rest_framework.generics import ListAPIView
class HotSKUAPIView(ListAPIView):

    pagination_class = None
    serializer_class = HotSerializer

    # queryset = SKU.objects.all()
    # queryset = SKU.objects.filter(category_id=category_id).order_by('-sales')[:2]

    # def get_queryset(self):
    #     category_id = self.kwargs['category_id']
    #
    #     return SKU.objects.filter(category_id=category_id).order_by('-sales')[:2]
    def get_queryset(self):
        category_id = self.kwargs['category_id']
        return SKU.objects.filter(category_id=category_id).order_by('-sales')[:2]

from rest_framework.filters import OrderingFilter
from rest_framework.pagination import LimitOffsetPagination, PageNumberPagination
"""
    抽取
"""
# class CustomPageNumberPagination(PageNumberPagination):
#
#     page_size = 2
#     page_size_query_param = 'page_size'


class SKUAPIView(ListAPIView):
    serializer_class = HotSerializer
    # 排序
    filter_backends = [OrderingFilter]
    ordering_fields = ['sales','price','create_time']

    # 分頁
    # pagination_class =CustomPageNumberPagination

    # 獲取數據
    def get_queryset(self):
        category_id = self.kwargs['category_id']

        return SKU.objects.filter(category_id=category_id)


def generic_list():

    pass


"""
數據  --> haystack( 虛擬環境中執行  rebuild_index ) --> elasticsearch

"""

from .serializers import SKUIndexSerializer
from drf_haystack.viewsets import HaystackViewSet

class SKUSearchViewSet(HaystackViewSet):
    """
    SKU搜索
    """
    index_models = [SKU]

    serializer_class = SKUIndexSerializer



